<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属试验室id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入所属试验室id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属项目id" prop="projectId">
        <el-input
          v-model="queryParams.projectId"
          placeholder="请输入所属项目id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属标段id" prop="bdId">
        <el-input
          v-model="queryParams.bdId"
          placeholder="请输入所属标段id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同号" prop="contractNo">
        <el-input
          v-model="queryParams.contractNo"
          placeholder="请输入合同号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['jl_base:baseBsContract:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['jl_base:baseBsContract:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['jl_base:baseBsContract:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['jl_base:baseBsContract:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseBsContractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="contractId" v-if="true"/>
      <el-table-column label="所属试验室id" align="center" prop="deptId" />
      <el-table-column label="所属项目id" align="center" prop="projectId" />
      <el-table-column label="所属标段id" align="center" prop="bdId" />
      <el-table-column label="合同号" align="center" prop="contractNo" />
      <el-table-column label="施工单位id" align="center" prop="sgdwId" />
      <el-table-column label="监理单位id" align="center" prop="jldwId" />
      <el-table-column label="建设单位id" align="center" prop="jsdwId" />
      <el-table-column label="是否允许修改flag" align="center" prop="updateFlag" />
      <el-table-column label="审核状态" align="center" prop="approveFlag" />
      <el-table-column label="是否允许负计量" align="center" prop="fjlFlag" />
      <el-table-column label="开工日期" align="center" prop="beginDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="竣工日期" align="center" prop="endDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同总价金额" align="center" prop="contractMoney" />
      <el-table-column label="合同清单总价金额" align="center" prop="contractSheetTotalMoney" />
      <el-table-column label="开工预付款金额" align="center" prop="kgyfkMoney" />
      <el-table-column label="材料预付款金额" align="center" prop="clyfkMoney" />
      <el-table-column label="暂列金金额" align="center" prop="zljMoney" />
      <el-table-column label="质保金金额" align="center" prop="zbjMoney" />
      <el-table-column label="计日工金额" align="center" prop="jrgMoney" />
      <el-table-column label="起讫桩号" align="center" prop="qqzh" />
      <el-table-column label="标段长度(KM)" align="center" prop="bdLen" />
      <el-table-column label="开工预付款起扣比例(%)" align="center" prop="kgyfkQkbl" />
      <el-table-column label="开工预付款截止比例(%)" align="center" prop="kgyfkJzbl" />
      <el-table-column label="质保金扣款比例(%)" align="center" prop="zbjKkbl" />
      <el-table-column label="农民工工资保证金扣款比例(%)" align="center" prop="nmggzbzjKkbl" />
      <el-table-column label="开工预付款支付情况" align="center" prop="kgyfkZfqk" />
      <el-table-column label="开工预付款扣回规定" align="center" prop="kgyfkKhgd" />
      <el-table-column label="材料预付款支付情况" align="center" prop="clyfkZfqk" />
      <el-table-column label="材料预付款扣回规定" align="center" prop="clyfkKhgd" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['jl_base:baseBsContract:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['jl_base:baseBsContract:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改合同主对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属试验室id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入所属试验室id" />
        </el-form-item>
        <el-form-item label="所属项目id" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入所属项目id" />
        </el-form-item>
        <el-form-item label="所属标段id" prop="bdId">
          <el-input v-model="form.bdId" placeholder="请输入所属标段id" />
        </el-form-item>
        <el-form-item label="合同号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同号" />
        </el-form-item>
        <el-form-item label="施工单位id" prop="sgdwId">
          <el-input v-model="form.sgdwId" placeholder="请输入施工单位id" />
        </el-form-item>
        <el-form-item label="监理单位id" prop="jldwId">
          <el-input v-model="form.jldwId" placeholder="请输入监理单位id" />
        </el-form-item>
        <el-form-item label="建设单位id" prop="jsdwId">
          <el-input v-model="form.jsdwId" placeholder="请输入建设单位id" />
        </el-form-item>
        <el-form-item label="是否允许修改flag" prop="updateFlag">
          <el-input v-model="form.updateFlag" placeholder="请输入是否允许修改flag" />
        </el-form-item>
        <el-form-item label="审核状态" prop="approveFlag">
          <el-input v-model="form.approveFlag" placeholder="请输入审核状态" />
        </el-form-item>
        <el-form-item label="是否允许负计量" prop="fjlFlag">
          <el-input v-model="form.fjlFlag" placeholder="请输入是否允许负计量" />
        </el-form-item>
        <el-form-item label="开工日期" prop="beginDate">
          <el-date-picker clearable
            v-model="form.beginDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择开工日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="竣工日期" prop="endDate">
          <el-date-picker clearable
            v-model="form.endDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择竣工日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同总价金额" prop="contractMoney">
          <el-input v-model="form.contractMoney" placeholder="请输入合同总价金额" />
        </el-form-item>
        <el-form-item label="合同清单总价金额" prop="contractSheetTotalMoney">
          <el-input v-model="form.contractSheetTotalMoney" placeholder="请输入合同清单总价金额" />
        </el-form-item>
        <el-form-item label="开工预付款金额" prop="kgyfkMoney">
          <el-input v-model="form.kgyfkMoney" placeholder="请输入开工预付款金额" />
        </el-form-item>
        <el-form-item label="材料预付款金额" prop="clyfkMoney">
          <el-input v-model="form.clyfkMoney" placeholder="请输入材料预付款金额" />
        </el-form-item>
        <el-form-item label="暂列金金额" prop="zljMoney">
          <el-input v-model="form.zljMoney" placeholder="请输入暂列金金额" />
        </el-form-item>
        <el-form-item label="质保金金额" prop="zbjMoney">
          <el-input v-model="form.zbjMoney" placeholder="请输入质保金金额" />
        </el-form-item>
        <el-form-item label="计日工金额" prop="jrgMoney">
          <el-input v-model="form.jrgMoney" placeholder="请输入计日工金额" />
        </el-form-item>
        <el-form-item label="起讫桩号" prop="qqzh">
          <el-input v-model="form.qqzh" placeholder="请输入起讫桩号" />
        </el-form-item>
        <el-form-item label="标段长度(KM)" prop="bdLen">
          <el-input v-model="form.bdLen" placeholder="请输入标段长度(KM)" />
        </el-form-item>
        <el-form-item label="开工预付款起扣比例(%)" prop="kgyfkQkbl">
          <el-input v-model="form.kgyfkQkbl" placeholder="请输入开工预付款起扣比例(%)" />
        </el-form-item>
        <el-form-item label="开工预付款截止比例(%)" prop="kgyfkJzbl">
          <el-input v-model="form.kgyfkJzbl" placeholder="请输入开工预付款截止比例(%)" />
        </el-form-item>
        <el-form-item label="质保金扣款比例(%)" prop="zbjKkbl">
          <el-input v-model="form.zbjKkbl" placeholder="请输入质保金扣款比例(%)" />
        </el-form-item>
        <el-form-item label="农民工工资保证金扣款比例(%)" prop="nmggzbzjKkbl">
          <el-input v-model="form.nmggzbzjKkbl" placeholder="请输入农民工工资保证金扣款比例(%)" />
        </el-form-item>
        <el-form-item label="开工预付款支付情况" prop="kgyfkZfqk">
          <el-input v-model="form.kgyfkZfqk" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="开工预付款扣回规定" prop="kgyfkKhgd">
          <el-input v-model="form.kgyfkKhgd" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="材料预付款支付情况" prop="clyfkZfqk">
          <el-input v-model="form.clyfkZfqk" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="材料预付款扣回规定" prop="clyfkKhgd">
          <el-input v-model="form.clyfkKhgd" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBaseBsContract, getBaseBsContract, delBaseBsContract, addBaseBsContract, updateBaseBsContract } from "@/api/jl_base/baseBsContract";

export default {
  name: "BaseBsContract",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 合同主表格数据
      baseBsContractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: undefined,
        projectId: undefined,
        bdId: undefined,
        contractNo: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectId: [
          { required: true, message: "所属项目id不能为空", trigger: "blur" }
        ],
        bdId: [
          { required: true, message: "所属标段id不能为空", trigger: "blur" }
        ],
        contractNo: [
          { required: true, message: "合同号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询合同主列表 */
    getList() {
      this.loading = true;
      listBaseBsContract(this.queryParams).then(response => {
        this.baseBsContractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        contractId: undefined,
        deptId: undefined,
        projectId: undefined,
        bdId: undefined,
        contractNo: undefined,
        sgdwId: undefined,
        jldwId: undefined,
        jsdwId: undefined,
        updateFlag: undefined,
        approveFlag: undefined,
        fjlFlag: undefined,
        beginDate: undefined,
        endDate: undefined,
        contractMoney: undefined,
        contractSheetTotalMoney: undefined,
        kgyfkMoney: undefined,
        clyfkMoney: undefined,
        zljMoney: undefined,
        zbjMoney: undefined,
        jrgMoney: undefined,
        qqzh: undefined,
        bdLen: undefined,
        kgyfkQkbl: undefined,
        kgyfkJzbl: undefined,
        zbjKkbl: undefined,
        nmggzbzjKkbl: undefined,
        kgyfkZfqk: undefined,
        kgyfkKhgd: undefined,
        clyfkZfqk: undefined,
        clyfkKhgd: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.contractId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加合同主";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const contractId = row.contractId || this.ids
      getBaseBsContract(contractId).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改合同主";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.contractId != null) {
            updateBaseBsContract(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addBaseBsContract(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const contractIds = row.contractId || this.ids;
      this.$modal.confirm('是否确认删除合同主编号为"' + contractIds + '"的数据项？').then(() => {
        this.loading = true;
        return delBaseBsContract(contractIds);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('jl_base/baseBsContract/export', {
        ...this.queryParams
      }, `baseBsContract_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
